<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="head_back posabs zin-1 wth100">
		</view>
		<view class="background_f pad20 min30 rad1 column">
			<view class="font600 size30" style="color: #2E3C2A;">
				基本信息
			</view>
			<view class="row padbottom20 mintop30 align_item_c border_bottom">
				<view class="font600 size28" style="color: #2E3C2A;width: 80px;">
					姓名
				</view>
				<u--input placeholder="请输入您的真实姓名" placeholderStyle="font-size: 28rpx;" border="none"
					v-model="name"></u--input>
			</view>
			<view class="row padbottom20 mintop30 align_item_c border_bottom">
				<view class="font600 size28" style="color: #2E3C2A;width: 80px;">
					身份证
				</view>
				<u--input placeholder="请输入身份证号" maxlength="18" placeholderStyle="font-size: 28rpx;" border="none"
					v-model="IDcard"></u--input>
			</view>
			<view class="row padbottom20 mintop30 align_item_c border_bottom">
				<view class="font600 size28" style="color: #2E3C2A;width: 80px;">
					手机号
				</view>
				<u--input placeholder="请输入手机号" maxlength="11" type="number" placeholderStyle="font-size: 28rpx;"
					border="none" v-model="phone"></u--input>
			</view>
		</view>
		<view class="pad20 min30_rl rad1 column box">
			<view class="size30 font600 col0 text_center minbottom20">
				申请业务员规则说明
			</view>
			<view class="">
				<mp-html :content="html" />
			</view>
		</view>
		<view class="min30 padtop40">
			<u-button text="提交申请" shape="circle" color="linear-gradient( 90deg, #FFCC48 0%, #FF984E 100%)"
				@click="getApply">
			</u-button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				screenWidth: '',
				name: '',
				phone: '',
				IDcard: '',
				img_url: '',
				user_id: '',
				html: '<div>Hello World!</div>',
				fileList1: []
			}
		},

		onLoad() {
			let app = uni.getSystemInfoSync()
			this.screenWidth = app.screenWidth - 135
			this.user_id = uni.getStorageSync('user_id');
			this.getUserinfo()
			this.getAgreement()
		},
		methods: {
			async getAgreement() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("home/agreement")
				if (code == 200) {
					this.html = data.salesman_application
			
				} else {
					console.log(message);
				}
			},
			async getUserinfo() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/user_info/" + this.user_id)
				if (code == 200) {
					this.phone = data.phone

				} else {
					console.log(message);
				}
			},
			async getApply() {
				var _this = this
				var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
				var id =
					/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/;
				if (!_this.name) return this.$com.toast('请输入您的真实姓名');
				if (!_this.IDcard) return this.$com.toast('请输入身份证号');
				if (!id.test(_this.IDcard)) return this.$com.toast('身份证号输入不正确');
				if (!_this.phone) return this.$com.toast('请输入手机号');
				if (!strTemp.test(_this.phone)) return this.$com.toast('手机号输入不正确');
				let {
					code,
					message,
					data
				} = await this.$com.fetch('member/application_Salesman/' + this.user_id, {
					phone: _this.phone,
					salesman_id_card: _this.IDcard,
					salesman_name: _this.name,
				});

				if (code == 200) {
					uni.showToast({
						icon: 'success',
						title: message
					})
					setTimeout(function() {
						uni.switchTab({
							url: '/pages/user/my'
						});
					}, 1000)
				} else {
					uni.showToast({
						icon: 'none',
						title: message
					})
				}

			},
		}
	}
</script>

<style scoped lang="less">
	.head_back {
		background: linear-gradient(63deg, #FF515E 0%, #FF7F3E 100%), linear-gradient(167deg, #FF6B4A 0%, rgba(255, 123, 77, 0) 100%);
		top: 0;
		height: 200rpx;
	}

	.border_bottom {
		border-bottom: 2rpx solid #EDEDED;
	}

	.box {
		background: linear-gradient(180deg, #FFC690 0%, #FFFFFF 34%);
	}
</style>